package Views;

import Source.CreateManager;
import UCM.UCCreateManager;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

/**
 *
 * @author Joshua King
 */
public class ViewCreateManager extends JPanel {
    private static String TEXT = "Error!111ewrc";
    private static String TEXT2 = "Success!LKJAS";
    private static int MAXCHAR = 10;
    private JLabel userLabel = new JLabel("Name: ");
    private JLabel passwordLabel = new JLabel("Password: ");  
    private JLabel confirmPasswordLabel = new JLabel("Retype Password: ");  
    private JLabel firstNameLabel = new JLabel("First Name: ");
    private JLabel lastNameLabel = new JLabel("Last Name: ");
    private JLabel addressLabel = new JLabel("Address: ");
    private JTextField user = new JTextField(MAXCHAR);
    private JPasswordField password = new JPasswordField(MAXCHAR);
    private JPasswordField confirmPassword = new JPasswordField(MAXCHAR);
    private JTextField firstName = new JTextField(MAXCHAR);
    private JTextField lastName = new JTextField(MAXCHAR);
    private JTextField address = new JTextField(MAXCHAR);
    private JButton createManagerBtn = new JButton("Create Manager");
    private UCCreateManager UCCreateManager = new UCCreateManager(this);
    private CreateManager model;
    
    public ViewCreateManager() {
        add(userLabel);
        add(user);
        add(passwordLabel);
        add(password);
        add(confirmPasswordLabel);
        add(confirmPassword);
        add(firstNameLabel);
        add(firstName);
        add(lastNameLabel);
        add(lastName);
        add(addressLabel);
        add(address);
        add(createManagerBtn);
        createManagerBtn.addActionListener(new AdapterUCCToAL(UCCreateManager));
        validate();
    }
    
    public void loadTo (CreateManager model) {
        this.model = model;
    }
    
    public void loadData() {
        model.setUser(user.getText());
        model.setFirstName(firstName.getText());
        model.setLastName(lastName.getText());
        model.setAddress(address.getText());
        model.setPassword(new String(password.getPassword()));
        model.setConfirmPassword(new String(confirmPassword.getPassword()));
    }


    public void updateFailure() {
        ViewMain.getInstance().updateMsg(TEXT);
    }

    public void updateSuccess() {
        //setText("");
        user.setText("");
        password.setText("");
        confirmPassword.setText("");
        firstName.setText("");
        lastName.setText("");
        address.setText("");
        ViewMain.getInstance().updateMsg(TEXT2);
    }

}
